/**
 * Copyright (c) 1995-2011 Hundsun Technologies Inc. All Rights Reserved
 * Create on Jun 27, 2011
 * Author:coolsun;
 */
package com.dwusoft.banks.tradeBank.common.utils;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public final class SpringBeanFactory implements ApplicationContextAware, BeanFactoryPostProcessor, DisposableBean{

	private static ApplicationContext applicationContext;
	
	
	@SuppressWarnings("unchecked")
    public static <T> T getBean(String beanName){
		return (T)applicationContext.getBean(beanName);
	}
	
	
	public void setApplicationContext(ApplicationContext applicationContext) {
		SpringBeanFactory.applicationContext = applicationContext;
	}	

	

	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
			throws BeansException {
	}

	public void destroy() throws Exception {
		applicationContext =null;
    }
	
}
